﻿@{
    ViewBag.Title = "MonthReportIndex";
    Layout = "~/Views/Shared/_Form.cshtml";
    //报表链接
    var reportUrl = SysConfigReader.OrgReportLink();
}

<div class="rows">
    <div class="panel panel-default">
        <table class="form">
            <tr>
                <th class="formTitle">住院号：</th>
                <td class="formValue">
                    <input id="zyh" name="zyh" type="text" autocomplete= "off" class="form-control" />
                </td>
                <th class="formTitle">开始日期：</th>
                <td class="formValue">
                    <input id="ksrq" type="text" class="form-control input-wdatepicker formClearIgnore" style="width:90px" 
                           onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" 
                           onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', onpicked: function () { refReport(); } })" 
                           value="@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")" />
                </td>
                <th class="formTitle">结束日期：</th>
                <td class="formValue">
                    <input id="jsrq" type="text" class="form-control input-wdatepicker formClearIgnore" style="width:90px" 
                           onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" 
                           onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', onpicked: function () { refReport(); } })" 
                           value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                </td>
                <th class="formTitle"></th>
                <td class="formValue" style="padding-left:20px;">
                    <input type="button" id="btn_search" onclick="submit();" class="btn btn-primary btn-md" value="查询" style="width:55px" />
                </td>
                <th></th>
                <td></td>
                <th></th>
                <td></td>
            </tr>
        </table>
    </div>
</div>

<div class="ui-layout" id="layout" style="height:100%;width:100%;">
    <iframe class="ui-layout-center" style="width:100%;" id="iframerightiframerightiframerightttt" name="iframerightiframerightiframerightttt"
            scrolling="auto" allowtransparency="true" frameborder="0"></iframe>
</div>

<script type="text/javascript">
    var isHospAdministrator = '@(ViewBag.IsHospAdministrator)';
    var curUserCode = '@(ViewBag.CurUserCode)';

    //治疗项目选择浮层绑定
    $('#zyh').newtouchBatchFloatingSelector({
        width: 500,
        height: 200,
        caption: "选择患者",
        clickautotrigger: true,
        url: "/ReportManage/Report/GetInpatientcryrq",
        ajaxparameters: function ($thisinput) {
            var keyword = $thisinput.val().trim();
            var zyh = $("#zyh").val();
            return "zyh=" + zyh;
        },
        itemdbclickhandler: function ($thistr, $thisinput) {
            if (!!$thistr.attr('data-zyh')) {
                if ($thistr.attr('data-ryrq') !== "" && $thistr.attr('data-ryrq') !== undefined && $thistr.attr('data-ryrq') !== null) {
                    $('#ksrq').val($.getDate({ date: $thistr.attr('data-ryrq') }));
                }
                if ($thistr.attr('data-cyrq') !== "" && $thistr.attr('data-cyrq') !== undefined && $thistr.attr('data-cyrq') !== null) {
                    $('#jsrq').val($.getDate({ date: $thistr.attr('data-cyrq') }));
                } else {
                    $('#jsrq').val($.getDate());
                }
                $('#zyh').val($thistr.attr('data-zyh'));
                submit();
            }
        },
        colModel: [
            { label: '住院号', name: 'zyh', width: 100 },
            { label: 'cyrq', name: 'cyrq', hidden: true },
            { label: 'ryrq', name: 'ryrq', hidden: true },
            { label: '在院标志', name: 'zybz', width: 100, align: 'left' },
            { label: '姓名', name: 'xm', width: 120, align: 'left' },
            { label: '出生年月', name: 'csny', hidden: true, width: 100, align: 'left' },
            {
                label: '性别', name: 'xb', width: 50, align: 'left', formatter: function (cellvalue) {
                    return $.getGender(cellvalue);
                }
            },
            {
                label: '年龄', name: 'nlshow', width: 50, align: 'left', formatter: function (cellvalue, a, b) {
                    return getAgeFromBirthTime({ begin: b.csny }).text;
                }
            }
        ]
    });

    function submit() {

        if ($('#zyh').val().length == 0) {
            $.modalAlert("缺少住院号", "error");
            return;
        }
        if ($('#ksrq').val().length == 0 || $('#jsrq').val().length == 0) {
            $.modalAlert("请选择时间范围", "error");
            return;
        }
        
        //同步费用
        $.ajax({
            url: "/ReportManage/Report/SynInpatientDayFee",
            data: { zyh: $('#zyh').val() },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
            }
        })

        var url = getUrl();

        url += "&zyh=" + $('#zyh').val() + "&ksrq=" + $('#ksrq').val() + "&jsrq=" + $('#jsrq').val();

        setTimeout("$.loading(true, '正在请求报表页面...');", 10);
        $("#iframerightiframerightiframerightttt").attr('src', url);
    }

    $("#iframerightiframerightiframerightttt").load(function () {
        $.loading(false);
    });

    $(function () {
        var h = $(window).height() - 55
        $('#layout iframe').css('height', h);

    });

    //刷新列表
    function refReport() {
        $("#btn_search").trigger('click');
    }

    function getUrl() {
        var srcUrl = '@Html.Raw(reportUrl)';

        //获取自定义样式
        if (true) {
            if (srcUrl.indexOf('&rc:Stylesheet') == -1) {
                srcUrl += "&rc:Stylesheet=MyStyleSheet";
            }
        }
        if (false) {
            srcUrl += "&curUserCode=" + curUserCode;
        }
        if (false) {
            srcUrl += "&isHospAdministrator=" + isHospAdministrator;
        }

        return srcUrl;
    }

</script>
